﻿CREATE PROCEDURE [maint].[CreateContigResultsTable]
@TableName [sysname] OUTPUT, @OutputDiagnostics BIT=0
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @RC int
	SET @RC = 0

	IF(@OutputDiagnostics = 1)
		PRINT OBJECT_NAME(@@PROCID)

	SET @TableName = N'##' + REPLACE(CAST(NEWID() AS nvarchar(36)),'-','')
	IF(@OutputDiagnostics = 1)
		PRINT N'	@TableName = N''' + ISNULL(@TableName,N'NULL') + ''''

	DECLARE @CreateTableStatement nvarchar(453)
	SET @CreateTableStatement = N'CREATE TABLE [' + @TableName + N'] (
[ObjectName] char(255)
,[ObjectId] int
,[IndexName] char(255)
,[IndexId] int
,[Lvl] int
,[CountPages] int
,[CountRows] int
,[MinRecSize] int
,[MaxRecSize] int
,[AvgRecSize] int
,[ForRecCount] int
,[Extents] int
,[ExtentSwitches] int
,[AvgFreeBytes] int
,[AvgPageDensity] int
,[ScanDensity] decimal
,[BestCount] int
,[ActualCount] int
,[LogicalFrag] decimal
,[ExtentFrag] decimal
)'
	EXEC @RC = dbo.sp_executesql @CreateTableStatement

	RETURN(@RC)
END